/*
 * lambda.c
 *
 * Copyright (C) 2015 - kali
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

#include "include/types.h"
#include "include/parse.h"
#include "include/lexer.h"
#include "include/axioms.h"
//char *bos;
//int debug;


/**

	All right, now that I have some basic procedures down, I think that I
	want to take the time to reorganize how they are defined and loaded. As
	it currently stands I manually create a namespace in the main method.
	
	

**/

					// why is this const?
int main (int argc, const char * argv[]) {
	//char bosv;
//	bos = &bosv;
	//printf("bos: %i\n", bos);
	
//	if (argc > 1 && !strcmp(argv[1], "-d"))
//		debug = 1;
	
//	char buff[8192];
//	char *p;
	nspace *n = NULL;
	//n = define(n, (asym *) newsym("x"), newint(3));
	
	atom *fn = lmd_newfun(lmd_newcons(lmd_newsym("x"), NULL),
				lmd_ccons(lmd_newcons(lmd_newsym("x"), NULL)), n);
	n = lmd_bind(n, (asym *) lmd_newsym("identity"), fn);
	n = lmd_bind(n, lmd_csym(lmd_newsym("+")), lmd_newax(add));
	n = lmd_bind(n, lmd_csym(lmd_newsym("-")), lmd_newax(sub));
	n = lmd_bind(n, lmd_csym(lmd_newsym("*")), lmd_newax(mult));
	n = lmd_bind(n, lmd_csym(lmd_newsym("exit")), lmd_newax(quit));
	n = lmd_bind(n, lmd_csym(lmd_newsym("lambda")), lmd_newax(lambda));
	n = lmd_bind(n, lmd_csym(lmd_newsym("define")), lmd_newax(define));
	n = lmd_bind(n, lmd_csym(lmd_newsym("test")), lmd_newax(test));//test的功能就是打印n这个链表的所有节点name
	n = lmd_bind(n, lmd_csym(lmd_newsym("length")), lmd_newax(length));
	n = lmd_bind(n, lmd_csym(lmd_newsym("quote")), lmd_newax(quote));
	n = lmd_bind(n, lmd_csym(lmd_newsym("list?")), lmd_newax(listp));
	n = lmd_bind(n, lmd_csym(lmd_newsym("car")), lmd_newax(car));
	n = lmd_bind(n, lmd_csym(lmd_newsym("cdr")), lmd_newax(cdr));
	n = lmd_bind(n, lmd_csym(lmd_newsym("=")), lmd_newax(numeq));
	n = lmd_bind(n, lmd_csym(lmd_newsym("cons")), lmd_newax(cons));
	n = lmd_bind(n, lmd_csym(lmd_newsym("if")), lmd_newax(aif));
	n = lmd_bind(n, lmd_csym(lmd_newsym("null?")), lmd_newax(nullp));
	n = lmd_bind(n, lmd_csym(lmd_newsym("let")), lmd_newax(let));
	n = lmd_bind(n, lmd_csym(lmd_newsym("let*")), lmd_newax(lets));
	n = lmd_bind(n, lmd_csym(lmd_newsym("set!")), lmd_newax(set));
	n = lmd_bind(n, lmd_csym(lmd_newsym("letrec")), lmd_newax(letrec));
	n = lmd_bind(n, lmd_csym(lmd_newsym("apply")), lmd_newax(sapply));
	n = lmd_bind(n, lmd_csym(lmd_newsym("or")), lmd_newax(or));
	n = lmd_bind(n, lmd_csym(lmd_newsym("begin")), lmd_newax(begin));
	n = lmd_bind(n, lmd_csym(lmd_newsym("equal?")), lmd_newax(equal));
	n = lmd_bind(n, lmd_csym(lmd_newsym("print")), lmd_newax(sprint));
	n = lmd_bind(n, lmd_csym(lmd_newsym("defmacro")), lmd_newax(defmacro));
//	n = lmd_bind(n, csym(newsym("call/cc")), newax(callcc));
	n = lmd_bind(n, lmd_csym(lmd_newsym("<")), lmd_newax(lt));
	n = lmd_bind(n, lmd_csym(lmd_newsym("quasiquote")), lmd_newax(quasiquote));
	n = lmd_bind(n, lmd_csym(lmd_newsym("load")), lmd_newax(load));
	n = lmd_bind(n, lmd_csym(lmd_newsym("not")), lmd_newax(not));
	n = lmd_bind(n, lmd_csym(lmd_newsym("and")), lmd_newax(and));
	n = lmd_bind(n, lmd_csym(lmd_newsym("eq?")), lmd_newax(realeq));
	
	printf("zap -- western flyer\n");
	
	loadfile("bootstrap.scm", n);
	
	for (;;) {
		printf("> ");
		//gets(buff);
		//p = buff;
		lmd_print(eval(lmd_read(stdin), n));
		//print(read(&p));
		printf("\n");
	}
	
    return 0;
}
